package com.ruoyi.web.controller.Information;

import com.ruoyi.Information.domain.CommunityInfo;
import com.ruoyi.Information.service.ICommunityInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 社区信息发布Controller
 * 
 * @author xianyu
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/Information/info")
public class CommunityInfoController extends BaseController
{
    @Autowired
    private ICommunityInfoService communityInfoService;

    /**
     * 查询社区信息发布列表
     */
//    @PreAuthorize("@ss.hasPermi('Information:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityInfo communityInfo)
    {
        startPage();
        List<CommunityInfo> list = communityInfoService.selectCommunityInfoList(communityInfo);
        return getDataTable(list);
    }

    /**
     * 导出社区信息发布列表
     */
    @PreAuthorize("@ss.hasPermi('Information:info:export')")
    @Log(title = "社区信息发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityInfo communityInfo)
    {
        List<CommunityInfo> list = communityInfoService.selectCommunityInfoList(communityInfo);
        ExcelUtil<CommunityInfo> util = new ExcelUtil<CommunityInfo>(CommunityInfo.class);
        util.exportExcel(response, list, "社区信息发布数据");
    }

    /**
     * 获取社区信息发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('Information:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityInfoService.selectCommunityInfoById(id));
    }

    /**
     * 新增社区信息发布
     */
    @PreAuthorize("@ss.hasPermi('Information:info:add')")
    @Log(title = "社区信息发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityInfo communityInfo)
    {
        return toAjax(communityInfoService.insertCommunityInfo(communityInfo));
    }

    /**
     * 修改社区信息发布
     */
    @PreAuthorize("@ss.hasPermi('Information:info:edit')")
    @Log(title = "社区信息发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityInfo communityInfo)
    {
        return toAjax(communityInfoService.updateCommunityInfo(communityInfo));
    }

    /**
     * 删除社区信息发布
     */
    @PreAuthorize("@ss.hasPermi('Information:info:remove')")
    @Log(title = "社区信息发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityInfoService.deleteCommunityInfoByIds(ids));
    }
}
